package com.ruoyi.factory.bom.service.impl;


import java.math.BigDecimal;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.factory.bom.domain.BomCost;
import com.ruoyi.factory.bom.domain.BomData;
import com.ruoyi.factory.bom.domain.MaterialCost;
import com.ruoyi.factory.bom.domain.ProductCost;
import com.ruoyi.factory.bom.mapper.BomCostMapper;
import com.ruoyi.factory.bom.mapper.MaterialCostMapper;
import com.ruoyi.factory.bom.mapper.ProductCostMapper;
import com.ruoyi.factory.bom.service.IMaterialCostService;
import com.ruoyi.factory.bom.service.IUpdateMaterialPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 物料模型Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-10-23
 */
@Service
public class MaterialCostServiceImpl implements IMaterialCostService
{
    @Autowired
    private MaterialCostMapper materialCostMapper;

    @Autowired
    IUpdateMaterialPriceService upMaterPriceService;
    @Autowired
    private BomCostMapper bomCostMapper;

    @Autowired
    private ProductCostMapper productCostMapper;

    /**
     * 查询物料模型
     * 
     * @param id 物料模型主键
     * @return 物料模型
     */
    @Override
    public MaterialCost selectMaterialCostById(String id)
    {
        return materialCostMapper.selectMaterialCostById(id);
    }

    /**
     * 查询物料模型列表
     * 
     * @param materialCost 物料模型
     * @return 物料模型
     */
    @Override
    public List<MaterialCost> selectMaterialCostList(MaterialCost materialCost)
    {
        return materialCostMapper.selectMaterialCostList(materialCost);
    }

    /**
     * 新增物料模型
     * 
     * @param tRawMaterialCost 物料模型
     * @return 结果
     */
    @Override
    public int insertMaterialCost(MaterialCost tRawMaterialCost)
    {
        tRawMaterialCost.setCreateTime(DateUtils.getNowDate());
        return materialCostMapper.insertMaterialCost(tRawMaterialCost);
    }

    /**
     * 修改物料模型
     * 
     * @param materialCost 物料模型
     * @return 结果
     */
    @Override
    public int updateMaterialCost(MaterialCost materialCost)
    {
        materialCost.setUpdateTime(DateUtils.getNowDate());
        //修改原料价格
        int i = materialCostMapper.updateMaterialCost(materialCost);
        //添加修改物料人信息
        upMaterPriceService.upbomcostinfo(materialCost.getType(),materialCost);
        //修改物料价格之后同步bom成本
        upMaterPriceService.upbomcostafter(materialCost.getPartId());
        return i;
    }

    /**
     * 批量删除物料模型
     * 
     * @param ids 需要删除的物料模型主键
     * @return 结果
     */
    @Override
    public int deleteMaterialCostByIds(String[] ids)
    {
        return materialCostMapper.deleteMaterialCostByIds(ids);
    }

    /**
     * 删除物料模型信息
     * 
     * @param id 物料模型主键
     * @return 结果
     */
    @Override
    public int deleteMaterialCostById(String id)
    {
        return materialCostMapper.deleteMaterialCostById(id);
    }


}
